package com.sike.netty.jinjie.channelPipeline.userevent;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class CustomerEventHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof CustomEvent) {
            CustomEvent customEvent = (CustomEvent) evt;
            if ("type-01".equals(customEvent.getMessage())) {
                System.out.println("触发用户自定义事件，动态调整 ChannelHandler");
                // handler03 添加到 handler01 后
                ctx.channel().pipeline().addAfter("handler01","handler03",new DynamicChannelHandler03());
                // handler04 添加到 handler02 后
                ctx.channel().pipeline().addAfter("handler02","handler04",new DynamicChannelHandler04());
            }
        }

        super.userEventTriggered(ctx,evt);
    }
}
